package com.ckm.controller;

import com.ckm.annotation.LogInfo;
import com.ckm.entity.College;
import com.ckm.entity.ResponseResult;
import com.ckm.service.CollegeService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@LogInfo
@Validated
@RestController
@RequestMapping("college")
public class CollegeController {

    @Autowired
    private CollegeService collegeService;

    /**
     * 添加学院
     * @param collegeList 学院信息list
     * @return 成功信息
     */
    @PostMapping("addCollege")
    public ResponseResult addCollege(@RequestBody @Valid List<College> collegeList) {
        collegeService.addCollege(collegeList);
        return new ResponseResult(200,"添加成功",null);
    }

    /**
     * 更新学院
     * @param college 更新的信息
     * @return 成功信息
     */
    @PutMapping
    public ResponseResult updateCollege(@RequestBody College college) {
        collegeService.updateCollege(college);
        return new ResponseResult(200,"更新成功","");
    }

    /**
     * 删除学院
     * @param id 学院Id
     * @return 成功信息
     */
    @DeleteMapping
    public ResponseResult deleteCollege(@RequestParam(name = "id") Integer id) {
        collegeService.deleteCollege(id);
        return new ResponseResult(200,"删除成功","");
    }

    /**
     * 查找学院信息
     * @param college 查找词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return 分页结果集
     */
    @PostMapping("find")
    public ResponseResult findCollege(@RequestBody College college, @RequestParam(name = "pageNum",defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
        return new ResponseResult(200,"查找完毕",collegeService.getCollegePage(college,pageNum,pageSize));
    }
}
